# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName:   Auto_api_model
# FileName:      read_ini.py
# Author:       xgy
# Datetime:     2025/9/13 09:30
# Description:
# ---------------------------------------------------------------------------
import os
import configparser


class Ini:
    def __init__(self):
        # 获取data_config目录的路径
        self.data_config_path = os.path.join(os.path.dirname(os.path.dirname(__file__)),"data_config")
        # 获取Ini文件path
        ini_path = os.path.join(self.data_config_path,"config.ini")
        # 获取ini文件的对象
        self.conf = configparser.ConfigParser()
        # 使用ConfigParser对象的read方法读取ini文件
        res = self.conf.read(ini_path,encoding="utf=8")
    # 获取ini文件节点为file对应的key对应的值
    def get_file_path(self,key):
        try:
            file_name = self.conf.get("file",key)
        except Exception as e:
            # TODO  记录日志
            raise e
        else:
            return os.path.join(self.data_config_path,file_name)


    # 获取host节点下的的域名或ip:端口
    def get_host(self,key):
        try:
            return self.conf.get("host",key)
        except Exception as e:
            # TODO 记录日志
            raise e

    def get_table(self,key):
        try:
            return self.conf.get("table",key)
        except Exception as e:
            # todo 记录日志
            raise e



if __name__ == '__main__':
    ini = Ini()
    print(ini.get_file_path("case"))
    print(ini.get_host("bpm"))
    # 工具表的表名
    print(ini.get_table("name"))